package com.ecable.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Vector;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ecable.bean.PackagesTO;
import com.ecable.bean.VillageTO;
import com.ecable.daoImpl.PackagesDaoImpl;
import com.ecable.delegate.VillageMgrDelegate;
import com.ecable.exception.ConnectionException;
import com.ecable.exception.LoginException;
import com.ecable.util.UtilConstants;
import com.sun.org.apache.commons.beanutils.BeanUtils;

public class PackageUpdateAction extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -954350565195437778L;


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

			String path = "";
			RequestDispatcher rd = null;
			int packid=Integer.parseInt(request.getParameter("packid"));
			Vector<PackagesTO> vpack = new Vector<PackagesTO>();
			try {
				vpack = new PackagesDaoImpl().updateViewPackage(packid);
			} catch (Exception le) {
				request.setAttribute("status", UtilConstants._INVALID_PACKAGE);
				rd = request
						.getRequestDispatcher(UtilConstants._ADD_PACKAGE_FAILED);
			}

			if (!vpack.isEmpty()) {

				request.setAttribute("status",UtilConstants._PACKAGE_VIEW_SUCCESS);
				request.setAttribute("updatepackinfo",vpack);
				path = UtilConstants._VIEW_UPADATE_PACKAGE;

			} else {

				request.setAttribute("status", UtilConstants._PACKAGE_VIEW_SUCCESS);
				path = UtilConstants._VIEW_UPADATE_PACKAGE;

			}

			rd = request.getRequestDispatcher(path);

			rd.forward(request, response);
		}

	}